﻿namespace SampleApp.Tests.Pages
{
    using System.Linq;
    using Microsoft.Services.TestTools.UITesting.Html;
    using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;

    public class Home : Page {

        public static Home Launch() {
            return Launch<Home>();
        }

        //navigators

        public LogOn NavigateToLogOn() {
            Browser
                .Find<HtmlHyperlink>(new { InnerText = "Log On" })
                .Click();

            return NavigatedTo<LogOn>();
        }

        //actions

        public bool MainMenuContainsItem(string text) {
            return Browser
                .Find("menu")
                .GetChildren()
                .Any(x => x.GetInnerText() == text);
        }

        public bool IsLoggedInUserDisplayed(string userName) {
            return Browser
                .Find("logindisplay")
                .GetInnerText()
                .Contains(userName);
        }

        public void EnsureUserIsLoggedOff() {
            Browser.IfExists<HtmlHyperlink>(new { InnerText = "Log Off"}, e => e.Click());
        }
    }
}